package edenmedical;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Monitor;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Rectangle;


public class FrmVisDatiPeso implements Listener{
	private Display display;
	private Shell shell;
	private Text txtPeso;
	private Button btnStorico,btnChiudi;
	private Label lblData;
	private Text txtData;
	
	public FrmVisDatiPeso(String dispositivo,String[] dati)
	{
		this.display = Display.getCurrent();
		shell = new Shell(this.display);
		shell.setSize(333, 180);
		shell.setText("Misurazione " + dispositivo);
			
			lblData = new Label(shell, SWT.NONE);
			lblData.setBounds(19, 23, 24, 15);
			lblData.setText("Data");
			
			txtData = new Text(shell, SWT.BORDER);
			txtData.setBounds(114, 20, 193, 21);
			txtData.setEditable(false);
			txtData.setText(dati[0]);
		
			Label lblPeso = new Label(shell,SWT.NONE);
			lblPeso.setBounds(19, 59, 25, 15);
			lblPeso.setAlignment(SWT.CENTER);
			lblPeso.setText("Peso");
			txtPeso = new Text(shell,SWT.BORDER);
			txtPeso.setBounds(114, 56, 88, 21);
			txtPeso.setEditable(false);
			txtPeso.setText(dati[1]);
		
		btnStorico = new Button(shell,SWT.PUSH);
		btnStorico.setBounds(59, 109, 89, 25);
		btnStorico.setText("Mostra Storico");
		btnStorico.addListener(SWT.Selection, new Listener() {
			
			public void handleEvent(Event e) {
				FrmStoricoPeso frmStorico = new FrmStoricoPeso("Bilancia");
				frmStorico.Show();
		
			}
		});
		
		btnChiudi = new Button(shell,SWT.PUSH);
		btnChiudi.addListener(SWT.Selection, new Listener() {
			
			public void handleEvent(Event e) {
				shell.dispose();
		
			}
		});
		btnChiudi.setBounds(174, 109, 88, 25);
		btnChiudi.setText("Chiudi");
		btnChiudi.addListener(SWT.Selection,this);	
	}

	public void Show(){
		shell.open();
		Monitor primary = display.getPrimaryMonitor();
	    Rectangle bounds = primary.getBounds();
	    Rectangle rect = shell.getBounds();
	    int x = bounds.x + (bounds.width - rect.width) / 2;
	    int y = bounds.y + (bounds.height - rect.height) / 2;
	    shell.setLocation(x, y);
		while( !shell.isDisposed())
		{
			if(!display.readAndDispatch())
				display.sleep();
		}
	}

	public void handleEvent(Event e) {
		if (e.widget.equals(btnChiudi))
		{
			shell.dispose();
		}
	}
}
